package com.sykj.manage.web;

import java.util.Date;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.sykj.manage.service.SysWechatService;
import com.sykj.manage.model.SysWechat;
import com.sykj.util.ManageBody;
import com.sykj.util.PageUtil;
/**
 * 
 * @author 高志远
 *2018年9月13日下午3:48:36
 *类描述:微信[wechat_menu控制类
 */
@Controller
@RequestMapping("/sys")
public class SysWechatController {
	@Autowired
	SysWechatService sysWechatService;
	
	/**
	 * 微信菜单
	 * @param sysWechat
	 * @return
	 */
	@RequestMapping("/findWechat")
	@ResponseBody
	public ManageBody FindWechat(SysWechat sysWechat,Integer offset,Integer pageSize) {
		PageHelper.startPage(offset==null?1:PageUtil.getPageNum(offset, pageSize),pageSize==null?10:pageSize,true);
		List<SysWechat> wechats = sysWechatService.findWechat(sysWechat);
		PageInfo<SysWechat> pageInfo = new PageInfo<SysWechat>(wechats);
		return ManageBody.getData((int)pageInfo.getTotal(), pageInfo.getList(), "");
	}
	
	/**
	 * 删除菜单
	 * @param menu_id
	 * @return
	 */
	@RequestMapping("/delWechat")
	@ResponseBody
	public Object delWechat(@RequestParam("menu_id")String[] menu_id) {
		int cnt = sysWechatService.delWechat(menu_id);
		return cnt;
	}
	
	/**
	 * 
	 * @param sysWechat
	 * @return
	 * 添加角色
	 */
	@RequestMapping("/addWechat")
	@ResponseBody
	public Object addWechat(SysWechat sysWechat) {
		Date date = new Date();
		sysWechat.setCreate_time(date);
		int addcnt =sysWechatService.addWechat(sysWechat);
		return addcnt;
	}
	
	/**
	 * 按menu_id查询角色
	 * @param menu_id
	 * @return
	 */
	@RequestMapping("/findWechatById")
	@ResponseBody
	public Object findRoleById(@RequestParam("menu_id")String menu_id) {
		SysWechat wechat = sysWechatService.findWechatById(menu_id);
		return wechat;
	}
	
	/**
	 * 修改角色
	 * @param sysWechat
	 * @return
	 */
	@RequestMapping("/updWechat")
	@ResponseBody
	public Object updWechat(SysWechat sysWechat) {
		Date date = new Date();
		sysWechat.setModify_time(date);
		int updcnt = sysWechatService.updWechat(sysWechat);
		return updcnt;
	}

}
